#ifndef __LATCH_H__
#define __LATCH_H__

#include <boost/utility.hpp>
#include "mutex_lock.h"
#include "condition.h"

namespace mars {

/*
 * @brief 门闩，两种状态，开和关
 */
class Latch : boost::noncopyable {
    public:
        explicit Latch();
        /*
         * @brief 门闩没打开，就等待
         */
        void wait();

        /*
         * @brief 打开门闩
         */
        void open();

        /*
         * @brief 关闭门闩
         */
        void close();

    private:
        bool _status;
        MutexLock _mutex;
        Condition _cond;
};

} // namespace mars

#endif // __LATCH_H__
